﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using MvdDonk.Bomberman.Screens.Base;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using MvdDonk.Bomberman.Menu;

namespace MvdDonk.Bomberman.Screens
{
    /// <summary>
    /// A popup message box screen, used to display "are you sure?"
    /// confirmation messages.
    /// </summary>
    class MessageBoxScreen : MenuScreen
    {
        string message;
        


        public event EventHandler<EventArgs> Accepted;
        public event EventHandler<EventArgs> Cancelled;


        /// <summary>
        /// Constructor lets the caller specify whether to include the standard
        /// "A=ok, B=cancel" usage text prompt.
        /// </summary>
        public MessageBoxScreen(string message) :
            base(message, MenuOrientation.Horizontal)
        {
            // Create our menu entries.
            MenuEntry yesMenuEntry = new MenuEntry("Yes");
            MenuEntry noMenuEntry = new MenuEntry("No");

            // Hook up menu event handlers.
            yesMenuEntry.Selected += new EventHandler<EventArgs>(YesMenuEntry_Selected);
            noMenuEntry.Selected += new EventHandler<EventArgs>(NoMenuEntry_Selected);

            // Add entries to the menu.
            MenuEntries.Add(yesMenuEntry);
            MenuEntries.Add(noMenuEntry);

            this.message = message;

            IsPopup = true;

            TransitionOnTime = TimeSpan.FromSeconds(0.2);
            TransitionOffTime = TimeSpan.FromSeconds(0.2);
        }

        void YesMenuEntry_Selected(object sender, EventArgs e)
        {
            // Raise the accepted event, then exit the message box.
            if (Accepted != null)
                Accepted(this, new EventArgs());
            ExitScreen();
        }

        void NoMenuEntry_Selected(object sender, EventArgs e)
        {
            // Raise the cancelled event, then exit the message box.
            if (Cancelled != null)
                Cancelled(this, new EventArgs());

            ExitScreen();
        }





        ///// <summary>
        ///// Responds to user input, accepting or cancelling the message box.
        ///// </summary>
        //public override void HandleInput()
        //{
        //    if (Bomberman.Instance.InputManager.KeyClicked(Keys.Enter))
        //    {
        //        // Raise the accepted event, then exit the message box.
        //        if (Accepted != null)
        //            Accepted(this, new EventArgs());

        //        ExitScreen();
        //    }
        //    else if (Bomberman.Instance.InputManager.KeyClicked(Keys.Escape))
        //    {
        //        // Raise the cancelled event, then exit the message box.
        //        if (Cancelled != null)
        //            Cancelled(this, new EventArgs());

        //        ExitScreen();
        //    }
        //}


        /// <summary>
        /// Draws the message box.
        /// </summary>
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            base.Draw(gameTime, spriteBatch);

            /*
            SpriteFont font = ScreenManager.Font;

            // Darken down any other screens that were drawn beneath the popup.
            ScreenManager.FadeBackBufferToBlack(spriteBatch, TransitionAlpha * 2 / 3);

            // Center the message text in the viewport.
            Viewport viewport = Bomberman.Instance.GraphicsDevice.Viewport;
            Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);
            Vector2 textSize = font.MeasureString(message);
            Vector2 textPosition = (viewportSize - textSize) / 2;

            // The background includes a border somewhat larger than the text itself.
            const int hPad = 32;
            const int vPad = 16;

            Rectangle backgroundRectangle = new Rectangle((int)textPosition.X - hPad,
                                                          (int)textPosition.Y - vPad,
                                                          (int)textSize.X + hPad * 2,
                                                          (int)textSize.Y + vPad * 2);

            // Fade the popup alpha during transitions.
            Color color = Color.White * TransitionAlpha;

            spriteBatch.Begin();

            // Draw the background rectangle.
            spriteBatch.Draw(gradientTexture, backgroundRectangle, color);

            // Draw the message box text.
            spriteBatch.DrawString(font, message, textPosition, color);

            spriteBatch.End();
            */
        }

    }
}
